/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package certificate.database;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;

/**
 *
 * @author minhtuan
 */
public class ConnectionDB {

    static private Connection conn;
    private static String USER;
    private static String PASS;
    private static String DB_NAME;
    private static String HOST;
    private static String PORT;

    private static void getServer() {
        ResourceBundle bundle = ResourceBundle.getBundle("certificate.database.db");
        USER = bundle.getString("USER");
        PASS = bundle.getString("PASS");
        DB_NAME = bundle.getString("DB_NAME");
        HOST = bundle.getString("HOST");
        PORT = bundle.getString("PORT");        
    }

    public static Connection getConnection() throws SQLException {
        getServer();
        conn = DriverManager.getConnection("jdbc:sqlserver://" + HOST + ":" + PORT + ";user=" + USER + ";password=" + PASS + ";database=" + DB_NAME);
        return conn;
    }

    public static void closeConnection() throws SQLException {
        conn.close();
    }

    public static void main(String[] args) throws SQLException {
        ConnectionDB.getConnection();
    }
}
